/*
 * v1.1 by tonydon site:txdnet.cn
 * netbeansIDE 7.1
 */
package cn.txdnet.txcms.view.action;
import cn.txdnet.txcms.domain.Feedback;
import cn.txdnet.txcms.service.FeedbackService;
import cn.txdnet.txweb.annotation.methods.GetMethod;
import cn.txdnet.txweb.annotation.methods.PostMethod;
import cn.txdnet.txweb.model.ModelUtil;
import cn.txdnet.txweb.model.ModelView;
import cn.txdnet.txweb.utils.BeanUtil;
import cn.txdnet.txweb.utils.Message;
import cn.txdnet.txweb.utils.SessionUtil;
import cn.txdnet.txweb.utils.WebUtil;
import javax.servlet.http.HttpServletRequest;
import txdnet.util.Context;
/**
 *
 * @author txdnet
 */
public class FeedbackAction {
    
    @GetMethod
    public ModelView index(){ 
        return ModelUtil.getJspModel("post_form");
    }
 
    /*
     * 提交客户反馈保存到数据库
     */
    @PostMethod
    public ModelView save(HttpServletRequest req) throws Exception{
        String vcode = WebUtil.getNoNull(req, "vcode", null);
        String svcode = SessionUtil.getVcodeAndRemove(req);

        if(vcode==null || svcode==null || !svcode.equalsIgnoreCase(vcode)){
            return ModelUtil.getTextModel(Message.MSG_VCODE_ERR);
        }

        Feedback fb = BeanUtil.parseRequestToBean(Feedback.class, req);
                 fb.setIp(Context.getClientIp(req));
          if(! fb.validate() ){
              return ModelUtil.getTextModel(Message.MSG_FIELD_ERR);
          }
                 
         if(FeedbackService.make(fb)){
             return ModelUtil.getTextModel(Message.MSG_SUCCESS);
         }else{
             return ModelUtil.getTextModel(Message.MSG_FAIL);
         }

    }
}